<extend name="Public:main_module" />
<block name="h1_title">管理员帐号管理</block>
<block name="small_title">后台管理员列表</block>
<block name="other_headerinclude">
</block>
<block name="contents">			
<div class="form-group">
  <form class="navbar-form" role="search" action="" >
  	<div class="input-group pull-right no-margin">
	  <a href="#table-add" data-toggle="modal" >
	    <button class="btn btn-success">添加帐号</button>
	  </a>
    </div>
    
    <label class="sr-only" for="findRole">查找管理员:</label>
    <div class="input-group ">
      <input type="text" class="form-control" name="adminFilter" id="findRole" placeholder="{$adminFilter|default='查找管理员...'}">
    </div>
                  
	<div class="input-group ">
      <button type="submit" class="btn btn-sm btn-info">
                          <i class="icon-ok"></i>
                          过滤
      </button>
    </div>  	
  </form>
</div>						

<div class="row" id="main_div">
	<div class="col-xs-12">
		<!-- PAGE CONTENT BEGINS -->

		<div class="row">
			<div class="col-xs-12">
				<div class="table-responsive">
					<table id="sample-table-1" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th class="hidden-240">管理员帐号名</th>
								<th>管理员所属角色</th>
								<th>最后一次登录ip</th>
								<th>注册时间</th>
								<th>状态</th>
								<th>操作</th>
							</tr>
						</thead>

						<tbody>
						
						<volist name="list" id="vo">
							<tr>

								<td class="hidden-240">
									<strong>{$vo.username}</strong>
								</td>
								<td>{$vo.RoleName|default='该角色已被删除'}</td>
								<td>{$vo.last_ip|default='该帐号尚未登录过'}</td>
								<td>{$vo.create_time|date='Y-m-d H:i:s',###}</td>
								<td>
								<?php 	$is_active	= '<span class="label label-sm label-success">已启用</span>';
										$not_active	= '<span class="label label-sm label-inverse arrowed-in">已禁用</span>';?>
								<a href="javascript:" onclick="ChangeStatus({$vo.id},{$vo.is_active})" id="is_enabled{$vo.id}">{$vo['is_active']?$is_active:$not_active}</a>	
								</td>
								<td>
									<div class="visible-md visible-lg hidden-sm hidden-xs btn-group">

										
										<button class="btn btn-xs btn-info">
											<a href="#table-alter" data-toggle="modal" onclick="getRole({$vo['id']})" style="color:#fff;" ><i class="icon-edit bigger-120">编辑</i></a>
										</button>
                                        

										<button id="id-btn-dialog2" class="btn btn-xs btn-danger">
											<i class="icon-trash bigger-120" onclick="deleteConfirm({$vo['id']})">删除</i>
										</button>

									</div>

									<div class="visible-xs visible-sm hidden-md hidden-lg">
										<div class="inline position-relative">
											<button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown">
												<i class="icon-cog icon-only bigger-110"></i>
											</button>

											<ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
												<li>
													<a href="#" class="tooltip-info" data-rel="tooltip" title="View">
														<span class="blue">
															<i class="icon-zoom-in bigger-120"></i>
														</span>
													</a>
												</li>

												<li>
													<a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
														<span class="green">
															<i class="icon-edit bigger-120"></i>
														</span>
													</a>
												</li>

												<li>
													<a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
														<span class="red">
															<i class="icon-trash bigger-120"></i>
														</span>
													</a>
												</li>
											</ul>
										</div>
									</div>
								</td>
							</tr>
						</volist>

						</tbody>
					</table>
				</div><!-- /.table-responsive -->
				
				{$page}
							
			</div><!-- /span -->
		</div><!-- /row -->
			
		{:W('Windows/user_add')} 	
		
		{:W('Windows/user_update')} 
			
		<div class="hr hr-18 dotted hr-double"></div>

	</div><!-- /.col -->
</div><!-- /.row -->
</block>						
<block name="bottom_js">
<!-- inline scripts related to this page -->

<script type="text/javascript">
	jQuery(function($) {
		
		$('table th input:checkbox').on('click' , function(){
			var that = this;
			$(this).closest('table').find('tr > td:first-child input:checkbox')
			.each(function(){
				this.checked = that.checked;
				$(this).closest('tr').toggleClass('selected');
			});
				
		});
	
	
		$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
		function tooltip_placement(context, source) {
			var $source = $(source);
			var $parent = $source.closest('table')
			var off1 = $parent.offset();
			var w1 = $parent.width();
	
			var off2 = $source.offset();
			var w2 = $source.width();
	
			if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
			return 'left';
		}
	})
	
	//改变帐号状态
	function ChangeStatus(ids,active){
		var html_str	= active==1?'{$not_active}':'{$is_active}';
		$.get("__CONTROLLER__/user_update_status", { id: ids, is_active: active==1?0:1 },
		function(data){
			if(data){
				$("#is_enabled"+ids).html(html_str);
				$("#is_enabled"+ids).attr("onclick","ChangeStatus("+ids+","+(active==1?0:1)+")");
			}
		});		
	}
	
	//获取帐号数据
	function getRole(ids){
		$.get("__CONTROLLER__/user_get_data", { id: ids},
		function(data){
			if(data){
				$("#useraname").attr("value",data.username);
				$("#userId").attr("value",data.id);
				var op	= document.getElementById("forRoles");
				for(var i=0;i<op.length;i++){
					if(op[i].value==data.role_id){
						document.getElementById("forRoles")[i].selected=true;
					}
					else{
						document.getElementById("forRoles")[i].selected=false;
					}
				}
			}
		});	
	}	
	
	//删除帐号确认
	function deleteConfirm(id){
		if(confirm("确定要删除该帐号吗？")){
			window.location.href="__CONTROLLER__/deleteUser?id="+id;
		}
	}	
	
</script>
</block>